package com.wysql.ascost.model;

import lombok.Data;

/**
 * @title: R
 * @projectName: production-cost
 * @author: Zhang Jian
 * @date: 2023年07月21日 15:51
 */

@Data
public class R {
    private Integer code;

    private String msg;

    private Object data;

    /**
     * 构造器私有
     */
    private R() {
    }

    /**
     * 返回成功
     */
    public static R ok() {
        R r = new R();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMsg(ResponseEnum.SUCCESS.getMsg());
        return r;
    }

    public static R returnOk() {
        R r = new R();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        return r;
    }
    public static R returnErr() {
        R r = new R();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMsg(ResponseEnum.EXPORT_DATA_ERROR.getMsg());
        return r;
    }
    /**
     * 返回失败
     */
    public static R error() {
        R r = new R();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMsg(ResponseEnum.ERROR.getMsg());
        return r;
    }

    /**
     * 设置特定结果
     */
    public static R setResult(ResponseEnum responseEnum) {
        R r = new R();
        r.setCode(responseEnum.getCode());
        r.setMsg(responseEnum.getMsg());
        return r;
    }

    public R message(String msg) {
        this.setMsg(msg);
        return this;
    }

    public R code(Integer code) {
        this.setCode(code);
        return this;
    }

//    public R data(String key, Object value) {
//        this.data.put(key, value);
//        return this;
//    }

    public R data(Object map) {
        this.setData(map);
        return this;
    }


}